<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
        <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
        <title>归还钥匙</title>
        <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
        <link rel="stylesheet" href="../../script/ccssoft/css/ccssoft-lite.css" />
        <link rel="stylesheet" type="text/css" href="../../css/standBillRevertDetail.css" />
        <style>
            #header .openMenu-icon {
                display: inline-block;
                width: 40px;
                height: 40px;
                background: url(../../image/actionbar_icon_add.png) no-repeat center center;
                -webkit-background-size: 14px 18px;
                background-size: 30px 30px;
                position: absolute;
                right: 0;
                bottom: 0;
            }
            .iconFont {
                font-size: 22px;
                color: #8f8f94;
                height: 30px;
                line-height: 30px;
                display: inline-block;
                margin-top: 3px;
            }
            .activeWarning p {
                color: #DB4537;
            }
        </style>
        <style>
			.aui-flex-col:last-child {
				line-height: 25px;
				border-bottom: 1px dashed #00a0c8;
			}
			.aui-flex-col {
				line-height: 25px;
			}
			.cj-orange{
				background-color: orange;
			}
			.cj-blue{
				background-color: blue;
			}
			.cj-purple{
				background-color: purple;
			}
			.cj-green{
				background-color: green;
			}

			.cj-l-level{
				width: 18px;
				height: 18px;
				border-radius: 50%;
				line-height: 18px;
				text-align: center;
				display: inline-block;
				color: #fff;
				margin: 0 4px;
				vertical-align:top;
			}

			.cj-ash{
				background-color: grey;
			}
		 #main{
			 background-color: #f4f4f4;
			 padding-top: 10px;
		 }
		 .cj-l-into-wxx {
				 font-size: 12px;
				 color: #666;
				 line-height: 20px;
				 padding: 3px 0;
				 position: relative;
		 }
		 .cj-l-date-wxx {
				 display: block;
				 position: absolute;
				 top: 3px;
				 right: 0;
				 width: 180px;
				 text-align: right;
		 }
		 .cj-l-date-wxx span {
				 margin-left: 7px;
		 }
		 .cj-l-date-wxx:after {
				 content: "";
				 display: block;
				 width: 1px;
				 height: 12px;
				 background: #e3e3e3;
				 position: absolute;
				 top: 4px;
				 left: 60px;
		 }
		 .cj-l-date-wxx-2{
			 display: block;;
			 width: 1px;
			 height: 12px;
			 background: #e3e3e3;
			 position: absolute;
			 right: -4px;
			 top:4px;
		 }

		 .cj-l_line{
			 position: absolute;
			 width:5px;
			 height: 18px;
			 left: -10px;
			 top: 9px;
			 border-radius: 10px;
		 }
		 .cj-l_line1{
			 background: linear-gradient(#fe7a7d, #fe4f4f);
		 }
			.LC_img{
				height: 60px;
				display: block;
				margin: 0 auto;
				background-color:#ccc;
			}
			.wxx_btn_box{
				display: flex;
				justify-content: space-between;
			}
			.wxx_btn{
				width: 118px;
				height: 33px;
				border-radius: 35px;
				border: 1px solid #db4537;
				line-height: 30px;
				box-shadow: 0 3px 8px rgba(226,132,123,.5);
				color: #db4537;
				font-size: 14px;
				text-align: center;
				margin: 4px auto;
			}
			.none{
				display: none;
			}
		</style>
    </head>
    <body>
        <ul class="aui-list-view">
	        <li class="aui-list-view-cell border_b" >
			<li class="aui-list-view-cell border_b" >
				<div class="aui-col-xs-4 aui-pull-left red">借用人</div>
				<div class="aui-col-xs-7 aui-pull-right" id="operationUserName"></div>
			</li>
			<li class="aui-list-view-cell border_b" >
				<div class="aui-col-xs-4 aui-pull-left red">联系电话</div>
				<div class="aui-col-xs-7 aui-pull-right" id="arrivalsPhone"></div>
			</li>
			<li class="aui-list-view-cell border_b" >
				<div class="aui-col-xs-4 aui-pull-left red">钥匙编号</div>
				<div class="aui-col-xs-7 aui-pull-right" id="keyCode"></div>
			</li>
		</li>
	</ul>
	<div style="width: 100%; padding:0px; text-align:center; padding-top:10px; padding-bottom:10px">
		<button class="okBtn" style="width: 40%;color:#fff; margin:0px; float: none" onclick="submitData()">确定归还</button>
	</div>
	
    </body>
    <script src="../../script/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/doT.min.js"></script>
    <script type="text/javascript" src="../../script/common.js"></script>
    <script type="text/javascript" src="../../script/debug.js"></script>
    <script type="text/javascript" src="../../script/config.js"></script>
    <script type="text/javascript" src="../../script/client.api.js"></script>
    <script type="text/javascript" src="../../script/aui-alert.js"></script>
    <script type="text/javascript" src="../../script/request.js"></script>

    <script type="text/javascript">
    	var leaveStation = true;
    	var firstDate = new Date();
        apiready = function() {
        	initData();
        };
        
        function initData(){
        	api.showProgress({
			title : '加载中...',
			modal : false
		});
        	var billModel = $api.getStorage('standBillModel');
        	var user = $api.getStorage('user');
        	
		request.getKeyInfo = function (opts,callback) {
			service({
				url: "/enterStationKey/getKeyByBillSn.do",
				data: opts
			},callback)
		}
		var opts = {"billSn": billModel.billSn, "stationId": billModel.stationId};
		request.getKeyInfo(opts,function(ret, err) {
			api.hideProgress();
			if (ret) {
				if (ret.success) {
					//alert(JSON.stringify(ret));
					if (ret.data && ret.data.KEY_STATUS){
						//alert(1);
						$('#operationUserName').html(ret.data.USERNAME);
						$('#arrivalsPhone').html(ret.data.MOBILEPHONE);
						$('#keyCode').html(ret.data.KEY_CODE);
						if (ret.data.KEY_STATUS=='N'){
							api.alert({
								msg : "钥匙已经归还."
							});
							setTimeout(function() {
								api.closeWin();
							}, 2000);
						} 
					} else {
						api.alert({
							msg : "该工单没有借出钥匙."
						});
						setTimeout(function() {
							api.closeWin();
						}, 2000);
					}
					//alert(JSON.stringify(ret));
				} else {
					api.alert({
						msg : "系统错误。"
					});
					setTimeout(function() {
						api.closeWin();
					}, 2000);
				}
			}
		});
        }
        
               
        // 提交归还钥匙信息
        function submitData(){
        
        	api.confirm({
			title : "归还钥匙",
			msg : "确定要归还钥匙吗?",
			buttons : ["确定", "取消"]
		}, function(ret, err) {
			if (1 == ret.buttonIndex) {// 确定
				var billModel = $api.getStorage('standBillModel');
		        	var user = $api.getStorage('user');
				//leaveStation
				var opts = {};
				opts.billSn=billModel.billSn;
				opts.billId=billModel.id;
				opts.operationUser=user.userid;
				opts.operationUserName=user.username;
				opts.action='N';
				
				// 计算操作时长
				var endDate=new Date(); 
				opts.operatingCost = (endDate.getTime()-firstDate.getTime())/1000; 
				
				request.submitData = function (opts,callback) {
					service({
						url: "/enterStationKeyLogBean/saveReturnKey.do",
						data: opts
					},callback);
				}
				
				api.showProgress({
					title : '保存中',
					modal : true
				});
				request.submitData(opts,function(ret, err) {
					api.hideProgress();
					if (ret) {
						if (ret.success) {
							api.toast({
                            	msg : "成功提交归还钥匙信息",
                            	duration : 1000,
                            	location : 'middle'
							});
				    		setTimeout(function() {
								// api.closeWin();
								//直接返回列表
								api.closeToWin({
									name: 'churuzhan/standBillListWin',
									frameName: 'standBillListWin'
								});
								api.execScript({
									name: 'churuzhan/standBillListWin',
									frameName:'waitTaskList1',
									script: 'refreshList();'
								});
							}, 1000);
						} else {
							console.log(JSON.stringify(ret));
							api.alert({
								msg : "数据提交失败"
							});
						}
					}
				});
			}
		});
        }
        
        function null2zero(val){
        	if (null==val) return 0;
        	else return val;
        }
        
    </script>
</html>
